<!DOCTYPE HTML>
<!--
	Dimension by HTML5 UP
	html5up.net | @ajlkn
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
 <head>
  <title>
   Dimension by HTML5 UP
  </title>
  <!-- <meta charset="utf-8" /> -->
  <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> -->
  <meta charset="utf-8"/>
  <meta content="width=device-width,initial-scale=1.0" name="viewport"/>
  <link href="../../assets/css/article.css" rel="stylesheet"/>
  <link href="https://cdn.bootcss.com/highlight.js/9.15.8/styles/github.min.css" rel="stylesheet"/>
  <noscript>
   <link href="../../assets/css/noscript.css" rel="stylesheet"/>
  </noscript>
 </head>
 <body>
  <div id="app">
  </div>
  <!-- built files will be auto injected -->
 </body>
 <body class="is-preload">
  <!-- Wrapper -->
  <div id="wrapper">
   <!-- Main -->
   <div id="main">
    <article id="article">
     <h1 id="windows10-kafka-docker">
      Windows10 Kafka Docker 集群搭建
     </h1>
     <hr/>
     <h2 id="_1">
      简介
     </h2>
     <p>
      使用 Windows Docker Desktop 搭建 Kafka 集群
     </p>
     <h3 id="zookeeper">
      运行 Zookeeper
     </h3>
     <p>
      这里使用但 zk，使用docker启动即可
     </p>
     <p>
      ```shell script
     </p>
     <h1 id="_2">
      第一次启动
     </h1>
     <p>
      docker run -dit --name zk -p 2181:2181 zookeeper
     </p>
     <h1 id="_3">
      重启
     </h1>
     <p>
      docker restart zk
     </p>
     <h1 id="_4">
      查看日志
     </h1>
     <p>
      docker logs -f zk
     </p>
     <div class="codehilite">
      <pre><span></span><code><span class="o">###</span> <span class="err">运行</span> <span class="n">Kafka</span>
<span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="err">启动的命令如下，注意将下面的</span> <span class="mi">192</span><span class="p">.</span><span class="mi">168</span><span class="p">.</span><span class="mi">101</span><span class="p">.</span><span class="mi">104</span> <span class="err">换成自己的宿主机</span><span class="n">IP</span><span class="err">，运行后查看日志正常即可</span>

<span class="o">```</span><span class="n">shell</span> <span class="n">script</span>
<span class="o">#</span> <span class="err">第一次启动</span>
<span class="n">docker</span> <span class="n">run</span> <span class="o">-</span><span class="n">dit</span> <span class="c1">--name kafka0 -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.101.104:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.101.104:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka</span>

<span class="n">docker</span> <span class="n">run</span> <span class="o">-</span><span class="n">dit</span> <span class="c1">--name kafka1 -p 9093:9093 -e KAFKA_BROKER_ID=1 -e KAFKA_ZOOKEEPER_CONNECT=192.168.101.104:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.101.104:9093 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093 -t wurstmeister/kafka</span>

<span class="n">docker</span> <span class="n">run</span> <span class="o">-</span><span class="n">dit</span> <span class="c1">--name kafka2 -p 9094:9094 -e KAFKA_BROKER_ID=2 -e KAFKA_ZOOKEEPER_CONNECT=192.168.101.104:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.101.104:9094 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094 -t wurstmeister/kafka</span>

<span class="o">#</span> <span class="err">重启</span>
<span class="n">docker</span> <span class="k">restart</span> <span class="n">kafka0</span>
<span class="n">docker</span> <span class="k">restart</span> <span class="n">kafka1</span>
<span class="n">docker</span> <span class="k">restart</span> <span class="n">kafka2</span>

<span class="o">#</span> <span class="err">查看日志</span>
<span class="n">docker</span> <span class="n">logs</span> <span class="o">-</span><span class="n">f</span> <span class="n">kafka0</span>

<span class="o">#</span> <span class="err">删除</span><span class="n">kafka</span>
<span class="n">docker</span> <span class="n">rm</span> <span class="o">-</span><span class="n">f</span> <span class="n">kafka0</span>
<span class="n">docker</span> <span class="n">rm</span> <span class="o">-</span><span class="n">f</span> <span class="n">kafka1</span>
<span class="n">docker</span> <span class="n">rm</span> <span class="o">-</span><span class="n">f</span> <span class="n">kafka2</span>
</code></pre>
     </div>
     <h3 id="_5">
      测试
     </h3>
     <p>
      测试建立3的副本和5的partition，查看是否配置成功。然后在1和2上启动消费者，0生产消息
     </p>
     <p>
      ```shell script
     </p>
     <h1 id="partition">
      建立副本和partition
     </h1>
     <p>
      docker exec -ti kafka0 kafka-topics.sh --create --zookeeper 192.168.101.104:2181 --replication-factor 3 --partitions 5 --topic TestTopic
     </p>
     <h1 id="_6">
      查看信息
     </h1>
     <p>
      docker exec -ti kafka0 kafka-topics.sh --describe --zookeeper 192.168.101.104:2181 --topic TestTopic
docker exec -ti kafka1 kafka-topics.sh --describe --zookeeper 192.168.101.104:2181 --topic TestTopic
docker exec -ti kafka2 kafka-topics.sh --describe --zookeeper 192.168.101.104:2181 --topic TestTopic
     </p>
     <h1 id="kafka0">
      消费和生产，最后一个kafka0输出后在其他两个能看到
     </h1>
     <p>
      docker exec -ti kafka1 kafka-console-consumer.sh --bootstrap-server 192.168.101.104:9093 --topic TestTopic --from-beginning
docker exec -ti kafka2 kafka-console-consumer.sh --bootstrap-server 192.168.101.104:9094 --topic TestTopic --from-beginning
docker exec -ti kafka0 kafka-console-producer.sh --broker-list 192.168.101.104:9092 --topic TestTopic
     </p>
     <h1 id="_7">
      性能测试
     </h1>
     <p>
      docker exec -ti kafka0 kafka-producer-perf-test.sh --topic TestTopic --num-records 100000 --record-size 1000 --throughput 2000 --producer-props bootstrap.servers=192.168.101.104:9092
docker exec -ti kafka0 kafka-consumer-perf-test.sh --bootstrap-server 192.168.101.104:9092 --topic TestTopic --fetch-size 1048576 --messages 100000 --threads 1
     </p>
     <div class="codehilite">
      <pre><span></span><code><span class="o">###</span> <span class="n">kafka</span> <span class="n">manage</span>
<span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="o">&amp;</span><span class="n">ensp</span><span class="p">;</span><span class="err">使用</span><span class="n">docker启动后</span><span class="err">，访问</span><span class="p">:</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">9000</span><span class="o">/</span> <span class="p">,</span> <span class="err">点击添加</span><span class="k">cluster</span><span class="err">，输入前两个（名称和</span><span class="n">zk地址</span><span class="err">），保存即可</span>

<span class="o">```</span><span class="n">shell</span> <span class="n">script</span>
<span class="n">docker</span> <span class="n">run</span> <span class="o">-</span><span class="n">dit</span> <span class="o">-</span><span class="n">p</span> <span class="mi">9000</span><span class="p">:</span><span class="mi">9000</span> <span class="o">-</span><span class="n">e</span> <span class="n">ZK_HOSTS</span><span class="o">=</span><span class="ss">"192.168.101.104:2181"</span> <span class="n">hlebalbau</span><span class="o">/</span><span class="n">kafka</span><span class="o">-</span><span class="n">manager</span><span class="p">:</span><span class="k">stable</span>

<span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">9000</span><span class="o">/</span>
</code></pre>
     </div>
     <h2 id="_8">
      参考链接
     </h2>
     <ul>
      <li>
       <a href="https://blog.csdn.net/noaman_wgs/article/details/103757791">
        【Kafka精进系列003】Docker环境下搭建Kafka集群
       </a>
      </li>
      <li>
       <a href="https://blog.csdn.net/belalds/article/details/80575751">
        kafka如何彻底删除topic及数据
       </a>
      </li>
     </ul>
    </article>
   </div>
   <!-- Footer -->
   <footer id="footer">
    <p class="copyright">
     © Untitled. Design:
     <a href="https://html5up.net">
      HTML5 UP
     </a>
     .
    </p>
   </footer>
  </div>
  <!-- BG -->
  <div id="bg">
  </div>
  <!-- Scripts -->
  <script src="../assets/js/jquery.min.js">
  </script>
  <script src="../assets/js/browser.min.js">
  </script>
  <script src="../assets/js/breakpoints.min.js">
  </script>
  <script src="../assets/js/util.js">
  </script>
  <script src="../assets/js/main.js">
  </script>
 </body>
</html>
